package com.huawang.mdesign.model.service.vo;

import com.huawang.business.constants.ErrorCode;
import com.huawang.business.constants.ErrorLevelEnum;

public class BaseResponse<T> {
    private int code;
    private String title;
    private String message;
    private T data;
    private ErrorLevelEnum errorLevel;

    private static <T> BaseResponse<T> set(int code, String title, String message, T data, ErrorLevelEnum level) {
        BaseResponse<T> response = new BaseResponse<>();
        response.setCode(code);
        response.setTitle(title);
        response.setMessage(message);
        response.setData(data);
        response.setErrorLevel(level);
        return response;
    }

    public static BaseResponse<String> success() {
        return success("");
    }

    public static <T> BaseResponse<T> success(T data) {
        return set(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getTitle(), ErrorCode.SUCCESS.getMessage(), data
                , null);
    }

    public static <T> BaseResponse<T> error(ErrorCode re) {
        return set(re.getCode(), re.getTitle(), re.getMessage(), null, ErrorLevelEnum.ERROR);
    }

    public static <T> BaseResponse<T> error(int code, String msg) {
        return set(code, "", msg, null, ErrorLevelEnum.ERROR);
    }

    public static <T> BaseResponse<T> error(int code, String title, String msg) {
        return set(code, title, msg, null, ErrorLevelEnum.ERROR);
    }

    public static <T> BaseResponse<T> error(int code, String title, String msg, ErrorLevelEnum level) {
        return set(code, title, msg, null, level);
    }

    public int getCode() {
        return this.code;
    }

    public String getTitle() {
        return this.title;
    }

    public String getMessage() {
        return this.message;
    }

    public T getData() {
        return this.data;
    }

    public ErrorLevelEnum getErrorLevel() {
        return errorLevel;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setData(T data) {
        this.data = data;
    }

    public void setErrorLevel(ErrorLevelEnum errorLevel) {
        this.errorLevel = errorLevel;
    }
}
